package main

import (
	"net"
	"net/rpc"
)

type HelloService struct{}

func (h *HelloService) SayHi(greeting string, reply *string) error {
	*reply = "Hello, " + greeting
	return nil
}

func main() {
	// 1.实例化一个server
	listener, _ := net.Listen("tcp", ":8080")

	// 2.注册处理逻辑
	_ = rpc.RegisterName("HelloService", &HelloService{})

	// 3.启动服务
	for {
		conn, _ := listener.Accept()
		go rpc.ServeConn(conn)
	}
}
